import tkinter as tk
from tkinter import messagebox

def check_password(main_window):
    password_window = tk.Toplevel(main_window)
    password_window.title("Enter Password")
    password_window.geometry("300x150")
    password_window.focus_set()
    # 设置窗口始终置顶
    password_window.attributes('-topmost', True)

    password_label = tk.Label(password_window, text="Enter Password:", font=("Arial", 12))
    password_label.pack(pady=10)

    password_entry = tk.Entry(password_window, show="*", font=("Arial", 12))
    password_entry.pack(pady=10)

    def verify_password():
        entered_password = password_entry.get()
        if entered_password == "123321":  # 替换为实际的密码
            password_window.destroy()
            from setting_page import create_setting_menu
            create_setting_menu(main_window)
        else:
            messagebox.showerror("Error", "Incorrect password. Please try again.")

    verify_button = tk.Button(password_window, text="Verify", font=("Arial", 12), command=verify_password)
    verify_button.pack(pady=10)

def change_password(main_window):
    password_window = tk.Toplevel(main_window)
    password_window.title("Change Password")
    password_window.geometry("300x200")
    password_window.focus_set()

    current_password_label = tk.Label(password_window, text="Current Password:", font=("Arial", 12))
    current_password_label.pack(pady=10)

    current_password_entry = tk.Entry(password_window, show="*", font=("Arial", 12))
    current_password_entry.pack(pady=10)

    new_password_label = tk.Label(password_window, text="New Password:", font=("Arial", 12))
    new_password_label.pack(pady=10)

    new_password_entry = tk.Entry(password_window, show="*", font=("Arial", 12))
    new_password_entry.pack(pady=10)

    confirm_password_label = tk.Label(password_window, text="Confirm New Password:", font=("Arial", 12))
    confirm_password_label.pack(pady=10)

    confirm_password_entry = tk.Entry(password_window, show="*", font=("Arial", 12))
    confirm_password_entry.pack(pady=10)

    def save_new_password():
        current_password = current_password_entry.get()
        new_password = new_password_entry.get()
        confirm_password = confirm_password_entry.get()

        if current_password == "your_password":  # 替换为实际的当前密码
            if new_password == confirm_password:
                # 在这里更新密码，例如将新密码保存到配置文件或数据库中
                print("Password updated successfully!")
                password_window.destroy()
            else:
                messagebox.showerror("Error", "New passwords do not match. Please try again.")
        else:
            messagebox.showerror("Error", "Incorrect current password. Please try again.")

    save_button = tk.Button(password_window, text="Save", font=("Arial", 12), command=save_new_password)
    save_button.pack(pady=10)